package homework;

import java.util.Random;

//一、
class Worker {
    //私有属性
    private String name;
    private String job;
    private int salary;

    public Worker(String name, String job, int salary) {
        this.name = name;
        this.job = job;
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", job='" + job + '\'' +
                ", salary=" + salary +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    //增加方法doJob
    public int doJob(int months) {
        System.out.println(this.name + "工作了" + months + "个月,获得" + this.salary * months + "工资");
        return salary * months;
    }
}

//二、
class SuperWoker extends Worker {


    Random r = new Random();
    float f1 = r.nextFloat();
    public float bonus = (1 + f1);


    public int doJob(int months, int addtionalHours) {
        int b = (int) (months * super.getSalary() * bonus + bonus * getSalary() * addtionalHours / 100);
        System.out.println(super.getName() + "工作了" + months + "个月" + "且加班了" + addtionalHours + "个小时" + "获得了" + b + "工资");
        return b;
    }

    @Override
    public int doJob(int months) {
        int a = (int) ((months * getSalary()) * bonus);
        System.out.println(super.getName() + "工作了" + months + "个月，获得了" + a + "工资");
        return a;
    }


    public SuperWoker(String name, String job, int salary) {
        super(name, job, salary);
    }
}

public class Homework {
    public static void main(String[] args) {
        Worker worker = new Worker("梁金印", "软测", 3000);
        worker.doJob(6);
        SuperWoker superWoker = new SuperWoker("ljy", "软测", 3000);
        superWoker.doJob(3);
        superWoker.doJob(3, 8);
    }
}
